import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Class that handle Submission Date and Time
 */
public class getDate {
    public static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss";
    public static SimpleDateFormat simpledateformat = new SimpleDateFormat(DATE_FORMAT_NOW);

    /**
     * Get the current Date and Time
     */
    public static String dateandtime(){
      Calendar calendar = Calendar.getInstance();
      return simpledateformat.format(calendar.getTime());
    }
    
    /**
     * Calculate the differences time between current Date Time and submission due Date
     */
    public static int elapsedDay(String dueDateStr) throws ParseException {
    	Date dueDateTime = simpledateformat.parse(dueDateStr);           
    	Calendar dueDateCal = Calendar.getInstance();
    	dueDateCal.setTime(dueDateTime);
    	Calendar todayCal = Calendar.getInstance();
        int elapsedDay = 0;
        while (dueDateCal.before(todayCal)) {
        	dueDateCal.add(Calendar.DAY_OF_MONTH, 1);
        	elapsedDay++;
        }
    	return elapsedDay;
    }
}
